package com.fish.start.animation.views;

import android.content.Context;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.Gravity;

import com.fish.start.animation.AnimationSet;
import com.fish.start.animation.R;
import com.fish.start.animation.StartAnimationActivity;
import com.fish.start.animation.Attr.AbstractWay;
import com.fish.start.animation.Attr.BitmapWay;

public class FishLogoAnimationView extends FishView {
	private static final String tag = FishLogoAnimationView.class.getSimpleName();
	AbstractWay mAnimationAttr;
	StartAnimationActivity mStartAnimationActivity;
	public FishLogoAnimationView(Context aStartAnimationActivity) {
		super(aStartAnimationActivity);
		getHolder().addCallback(this);
		mStartAnimationActivity = (StartAnimationActivity)aStartAnimationActivity;
 		setCanvasDrawInterface(this);
		setAnimatonCallBack(this);
		setHandler(mStartAnimationActivity.mHahdler);
	}
	public FishLogoAnimationView(Context context, AttributeSet attrs) {
		super(context, attrs);
		getHolder().addCallback(this);
		mStartAnimationActivity = (StartAnimationActivity)context;
 		setCanvasDrawInterface(this);
		setAnimatonCallBack(this);
		setHandler(mStartAnimationActivity.mHahdler);
	}
	@Override
	public void draw(Canvas aCanvas){
		try{
			super.draw(aCanvas);
			mAnimationAttr = mAnimationSet.pop();
			drawCanvas(aCanvas ,mAnimationAttr);
		}catch(Exception e){
			handlerException(e);
		}
	}
	@Override
	public void drawSelf(Canvas aCanvas) {
		try{
			super.drawSelf(aCanvas);
		}catch(Exception e){
			handlerException(e);
		}
	} 
	@Override
	public void produceAnimation(AnimationSet mAnimations) {
		try{
			super.produceAnimation(mAnimations);
			AbstractWay aw = new BitmapWay(this,
					BitmapFactory.decodeStream(getResources().openRawResource(R.raw.fish_logo), null, getOpt()));
			aw.setLayoutGravity(Gravity.CENTER);
			aw.createAnimatons(mAnimations);
		}catch(Exception e){
			handlerException(e);
		}
	}
	@Override
	public void onStop() {
		//handler(FISH_GAME_VIEW_DRAW_STOP,null);
	}
	@Override
	public void onDestory() {
		super.onDestory();
		//handler(FISH_GAME_VIEW_DRAW_DESTORY,null);		
	}
}
